using System.IO;
using System.Web;
using Newtonsoft.Json;

namespace OpenWaves.ActivityFeed.Web.Handler
{
    public static class HttpRequestBaseExtensions
    {
        public static T DeserializeBody<T>(this HttpRequestBase request)
        {
            var serializer = JsonSerializer.Create(JsonNetSerializerSettings.Current);
            using (var jsonTextReader = new JsonTextReader(new StreamReader(new UnclosableStream(request.InputStream), request.ContentEncoding)))
            {
                return serializer.Deserialize<T>(jsonTextReader);
            }
        }
    }
}